<script setup>
import { ref } from "vue";
import { defineProps, defineExpose } from "vue"
import { extractAddressInfo } from '@/utils/index'
import { useActionSheet } from "@/hooks/useNavigation.js"
import { getBusinessHours } from '@/utils/time.js'

const props = defineProps({
  data: Object,
  time: Array,
  loading: Boolean
})

const showBottom = ref(false);
defineExpose({ showBottom });

const showImgView = ref(false);
const images = ref([
  "https://fastly.jsdelivr.net/npm/@vant/assets/apple-1.jpeg",
  "https://fastly.jsdelivr.net/npm/@vant/assets/apple-2.jpeg",
]);
const imgIndex = ref(0);
// 简介
const handeljianjie = () => (showBottom.value = true);
// 打开图片
const openImgView = () => {
  showImgView.value = true;
};
const onChange = (newIndex) => {
  imgIndex.value = newIndex;
};

const closeClick = () => {
  showBottom.value = false
}

const { show, actions, navigationClick, onSelect } = useActionSheet()

</script>

<template>
  <div class="infolists">
    <div class="detail-info">
      <template v-if="!loading">
        <div class="distt">
          <div class="fontsizw">
            {{ props.data?.scenicAreaName }}
            <span
              class="sub_title"
              v-if="props.data?.typeName"
              @click="openImgView"
            >
              {{ props.data?.typeName }}
            </span>
          </div>
          <div class="jianjie" @click="handeljianjie">
            简介<van-icon name="arrow" />
          </div>
        </div>

        <div class="detail_time">
          <div class="detail_List" v-if="props.data?.telephone">
            <img class="mr5" src="../../assets/images/icons/tell.png" alt="" />
            <a class="detail_List_text" :href="`tel:+86${props.data?.telephone}`">
              {{ props.data?.telephone }}
            </a>
          </div>
          <div class="detail_List">
            <img class="mr5" src="../../assets/images/icons/time.png" alt="" />
            <span class="co">
              <span class="detail_List_text">
                营业时间：
                <template v-if="time?.length">
                  {{ getBusinessHours(props.time) }}
                </template>
                <template v-else>
                  24小时营业
                </template>
              </span>
            </span>
          </div>
          <div class="detail_List" v-if="props.data?.address" @click="navigationClick">
            <img  class="mr5" src="../../assets/images/icons/add.png" alt="" />
            <span class="detail_List_text">
            <span>{{ extractAddressInfo(props.data?.address)  || "" }}
            </span>
          </span>
          </div>
        </div>
      </template>

      <van-skeleton v-else>
        <template #template>
          <div :style="{ display: 'flex', width: '100%' }">
            <div :style="{ flex: 1}">
              <van-skeleton-paragraph row-width="60%" />
              <van-skeleton-paragraph />
              <van-skeleton-paragraph />
            </div>
          </div>
        </template>
      </van-skeleton>

    </div>
    <slot></slot>
  </div>
  <!--  closeable-->
  <van-popup
    v-model:show="showBottom"
    round
    position="bottom"
    :style="{ 'max-height': '70%', 'overflow-y': 'hidden' }"
  >
    <div class="brief_introduction">
      <div class="header">
        <div class="notice-title">简介</div>
        <img
          class="image_close"
          @click="closeClick"
          src="@/assets/images/icons/close-666666.png"
          alt=""
        >
      </div>
      <div class="content">
        <slot name="desc"></slot>
      </div>
    </div>
  </van-popup>
  <!-- 图片预览 -->
  <van-image-preview
    v-model:show="showImgView"
    :images="images"
    @change="onChange"
    :show-index="false"
    closeable
    closeIconPosition="top-left"
  >
    <template v-slot:cover>
      <div class="room-detail">
        <p>精品大床房</p>
        <p>1张1.8米大床 | 2人入住 | 40㎡ | 1份早餐 不可取消</p>
        <div class="footer">
          <span>图片 {{ imgIndex + 1 }} / {{ images.length }}</span>
          <div>
            <span class="price">¥<span class="fz22 blod"> 880 </span>起</span>
            <van-button class="order-btn" type="primary">预订</van-button>
          </div>
        </div>
      </div>
    </template>
  </van-image-preview>

  <van-action-sheet
    v-model:show="show"
    :actions="actions"
    @select="(e) => onSelect(e, props.data)"
    cancel-text="取消"
    close-on-click-action
  />
</template>

<style lang="scss" scoped>
.brief_introduction{
  display: flex;
  flex-direction: column;
  padding: 2rem;
  overflow: hidden;
  height: 100%;
  .header{
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 2.8rem;
    margin-bottom: 1.5rem;
    .notice-title {
      font-size: 2rem;
      font-weight: bold;
    }
    .image_close{
      width: 1.4rem;
      height: 1.4rem;
    }
  }
  .content{
    max-height: calc(70vh - 4rem - 2.8rem - 1.5rem);
    display: flex;
    flex-direction: column;
    .desc_header{
      font-size: 1.6rem;
      font-weight: bold;
      color: #333333;
      margin-bottom: .5rem;
    }
  }
}
.detail-info {
  display: flex;
  flex-direction: column;
  align-content: center;
  padding-top: 20px;
  width: 100%;
  margin-top: 0.5333rem;
  border-radius: 10px;
  margin-bottom: 2rem;
}

.detail-info > div {
  display: flex;
  height: calc(100% / 3)
}

.detail-info > div:nth-of-type(2) {
  display: flex;
}

.detail-time {
  display: flex;
  flex-direction: column;
  align-content: center;
  justify-content: space-between;
  font-size: 1.1rem;
  font-weight: 600;
  color: #666666;
  span,
  img {
    vertical-align: middle;
  }
}

.detail-time > div:nth-of-type(1) {
  width: 100%;
  padding-left: 2rem;
  display: flex;
  box-sizing: border-box;
  align-items: center;
}

.detail-time > div:nth-of-type(2) {
  margin-top: 1.5rem;
  width: 100%;
  padding-left: 2rem;
  display: flex;
  box-sizing: border-box;
  align-items: center;
}

.infolists {
  backdrop-filter: blur(10px);
  width: 100%;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.95) 0%,
    #f9f8f3 100%
  );
  height: 100%;
  overflow-y: auto;
  border-top-left-radius: 3rem;
  border-top-right-radius: 3rem;
  margin-top: 3rem;
  opacity: 1;
  margin-bottom: 3rem;
  z-index: 999;
  // backdrop-filter: blur(4px);
  .detail-info {
    display: flex;
    flex-direction: column;
    align-content: center;
    padding-top: 20px;
    width: 100%;
    margin-top: 0.5333rem;
    border-radius: 10px;
    margin-bottom: 2rem;
    .distt {
      width: calc(100% - 4rem);
      display: flex;
      margin-bottom: 1.2rem;
      align-items: center;
      justify-content: space-between;
      padding: 0 2rem;
      .fontsizw {
        display: flex;
        align-items: center;
        font-size: 23px;
        font-weight: 600;
        flex: 1;
        margin-right: 1rem;
        .sub_title {
          width: 4.4rem;
          height: 1.7rem;
          padding: 0.2rem 0.5rem;
          margin-left: 0.4rem;
          margin-right: 0.4rem;
          text-align: center;
          font-size: 1.2rem;
          line-height: 1.7rem;
          color: #666;
          background: rgba(0, 0, 0, 0.06);
          border-radius: 0.3rem;
        }
      }
      .jianjie {
        height: 2.4rem;
        text-align: center;
        line-height: 2.4rem;
        background: rgba(0, 0, 0, 0.05);
        border-radius: 3rem;
        font-size: 1.4rem;
        padding: 0 .8rem 0 1.2rem;
      }
    }
    .detail_time {
      padding: 0 2rem;
      display: flex;
      flex-wrap: wrap;
      box-sizing: border-box;
      .detail_List {
        display: flex;
        align-items: center;
        margin-top: 1rem;
        margin-right: 1rem;
        .mr5 {
          margin-right: 0.5rem;
        }
        .detail_List_text {
          font-size: 1.4rem;
          color: #666666;
        }
      }
    }
  }
}

.room-detail {
  padding: 20px;
  line-height: 1.5;
  color: #ffffff;
  .footer {
    display: flex;
    margin-top: 50px;
    justify-content: space-between;
    align-items: center;
    & > span {
      display: inline-block;
      height: fit-content;
      padding: 4px 8px;
      font-size: 1.2rem;
      background: rgba(255, 255, 252, 0.1);
      border-radius: 23px 23px 23px 23px;
    }
  }
  .price {
    display: inline-block;
    height: 36px;
    line-height: 36px;
    padding: 0 12px;
    background: rgba(255, 255, 252, 0.11);
    border-top-left-radius: 6px;
    border-bottom-left-radius: 6px;
  }
  .order-btn {
    height: 36px;
    line-height: 36px;
    vertical-align: bottom;
    border-top-left-radius: 0px;
    border-bottom-left-radius: 0px;
    background: #fffffc;
    color: #4fac91;
    border: none;
    width: 90px;
  }
}
.ml10 {
  margin-left: 10px;
}
</style>
<style>
.van-image-preview__cover {
  top: initial;
  bottom: 10px;
  color: #ffffff;
}
</style>